/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

/*!
 * File: core_test.hpp
 */

#ifndef _CORE_TEST_HPP_
#define _CORE_TEST_HPP_

#include <iostream>
#include <string>

#include "core.hpp"

namespace middleware {
//-----------------------------------------------------------------------------
// Definitions
/*!
 * Test function for TaskDescriptor
 */
void CoreTest();
//-----------------------------------------------------------------------------
// Implementations
void CoreTest() {
	// Testing
	try {
		std::cout << "Creating core as default..." << std::endl;
		CORE mycore("mach1.config", "peer1");
		PeerConfiguration pc =
				CORE::GetPeerConfiguration(std::string("core.config.xml"));
		std::cout << pc.PeerAddress.get_ip() << std::endl;
		std::cout << pc.PeerAddress.get_port() << std::endl;
		std::cout << pc.PeerAddress.get_port_disc() << std::endl;
		std::cout << pc.PeerAddress.get_port_w() << std::endl;
		std::cout << pc.LogCTAPort << std::endl;
		std::cout << pc.PeerCapabilities.capab_bandwidth << std::endl;
		std::cout << pc.PeerCapabilities.capab_core_num << std::endl;
		std::cout << pc.PeerCapabilities.capab_cpu_mhz << std::endl;
		std::cout << pc.PeerCapabilities.capab_cpu_num << std::endl;
		std::cout << pc.PeerCapabilities.capab_hops << std::endl;
		std::cout << pc.PeerCapabilities.capab_ram_mb << std::endl;
		std::vector< Address >::iterator it = pc.PeerNeighbourhood.begin();
		for (it = pc.PeerNeighbourhood.begin();
				it != pc.PeerNeighbourhood.end(); it++) {
			std::cout << it->get_ip() << "-" << it->get_port() << "-" <<
					it->get_port_disc() << "-" << it->get_port_w() << std::endl;
		}
	} catch(std::exception& e) {
		std::cout << "Error: " << e.what() << std::endl;
	}
}
} /* middleware */

#endif
